*******************************************************************************
****		Figure 7 - PREDICTED WTP FROM VARYING FUNCTIONAL FORM
*******************************************************************************

use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

merge m:1 date hour using ".\data\clean\HV_ML_reliab.dta", keep(1 3) nogen 
gen reliabilityML=dist/p20_speedML-dist/p50_speedML
gen reliabilityHV=dist/p20_speedHV-dist/p50_speedHV
gen reliability_diff=reliabilityML-reliabilityHV
replace reliability_diff=0 if reliability_diff<0.01
keep if reliability_diff~=.
la var reliability_diff "Reliability"
*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
drop if ELspeed==.
drop if TT_dif_hr==.
drop if holiday==1
la var TT_dif_hr "Time in Hours"
drop if dow==0|dow==6
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
keep if hour>4 & hour<9
drop if TT_dif_hr<=0
forval p=1/5{
	g TT_dif_hr`p'=TT_dif_hr^`p'
	la var TT_dif_hr`p' "Time in Hours^`p'"
	}


estimates clear

***************************************************************************************
********            Linear Model
***************************************************************************************
qui reg charged_toll c.TT_dif_hr reliability_diff  , cluster(rt_id)
margins , at(TT_dif_hr=(0(.05).5)) post
est sto a1
/* marginsplot, name(WTPfromTT1, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75)
*/
***************************************************************************************
********            Quadratic Model
***************************************************************************************
qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr reliability_diff  , cluster(rt_id)

margins , at(TT_dif_hr=(0(.05).5)) post
est sto a2
/* marginsplot, name(WTPfromTT2, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75) ///
	addplot(WTPfromTT1) */

***************************************************************************************
********            Cubic Model
***************************************************************************************


qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr reliability_diff  , cluster(rt_id)

margins , at(TT_dif_hr=(0(.05).5)) post
est sto a3
/* marginsplot, name(WTPfromTT3, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75)
*graph export .\results\appendix\figs\fig13_cubic.png, replace
*/
***************************************************************************************
********            Quartic Model
***************************************************************************************

qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr reliability_diff  , cluster(rt_id)
margins , at(TT_dif_hr=(0(.05).5)) post
est sto a4

/*marginsplot, name(WTPfromTT4, replace) yline(0) title(WTP from Travel Time - Quintic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
		  xlabel(0(.1).5,format(%03.2f)) xtick(0(.05).55)
*/

***************************************************************************************
********            Qintic Model
***************************************************************************************

qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr reliability_diff  , cluster(rt_id)
margins , at(TT_dif_hr=(0(.05).5)) post
est sto a5

/* marginsplot, name(WTPfromTT3, replace) yline(0) title(WTP from Travel Time - Quintic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
		  xlabel(0(.1).5,format(%03.2f)) xtick(0(.05).55) */
*graph export .\results\appendix\figs\fig13_quintic.png, replace		


*********************************************************
****	Col 4	Power Model with Constant
*********************************************************

nl (charged_toll = {b0} + {b1}*TT_dif_hr^{b2} + {b3}*reliability_diff) , ///
	initial(b0 3 b1 10 b2 1 b3 10) vce(cl rt_id) variables(TT_dif_hr reliability_diff)
margins , at(TT_dif_hr=(0(.05).5)) post  
est sto a6
forval i=0/6{
	local `i'=`i'*5/60
}

coefplot a2 a3 a4 a5 a6 a1, at recast(line) cirecast(off) lc(black)  p1(lp(solid) lc(gs8)) ///
p2(lp(dot)) p3(lp(dash)) p4(lp(dash_dot)) p5(lp(shortdash))  p6(lp(longdash)) ///
	xlabel(`0' "0" `1' "5" `2' "10" `3' "15" `4' "20" `5' "25" `6' "30") ///
	legend(order(12 2 4 6 8 10) label(12 "Linear") label(2 "Quadratic") ///
 	label(4 "Cubic") label(6 "Quartic") label(8 "Quintic") label(10 "Power") ///
 	region(lwidth(none)) row(1) ring(0) pos(12)) ///
 	ytitle("WTP from Travel Time Savings (in dollars)" , height(8)) ///
 	xtitle("{&Delta}Travel Time (in minutes)") name(WTPfromTT_cons, replace) ///
 	ciopts(fc(gs8%40) lw(none)) yline(0, lc(black))   plotregion(style(none) margin(zero)) ///
 		ylabel(-20(10)20) ytick(-20(5)20) 

graph export ".\results\appendix\figs\AFB5pa.png", as(png) replace


***************************************************************************************
********            

********            
*					WITHOUT CONSTANT
********            

********            
***************************************************************************************

estimates clear

***************************************************************************************
********            Linear Model
***************************************************************************************
qui reg charged_toll c.TT_dif_hr reliability_diff  , nocons cluster(rt_id)
margins , at(TT_dif_hr=(0(.05).5)) post
est sto b1
/* marginsplot, name(WTPfromTT1, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75)
*/
***************************************************************************************
********            Quadratic Model
***************************************************************************************
qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr reliability_diff  , nocons  cluster(rt_id)

margins , at(TT_dif_hr=(0(.05).5)) post
est sto b2
/* marginsplot, name(WTPfromTT2, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75) ///
	addplot(WTPfromTT1) */

***************************************************************************************
********            Cubic Model
***************************************************************************************


qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr reliability_diff  , nocons  cluster(rt_id)

margins , at(TT_dif_hr=(0(.05).5)) post
est sto b3
/* marginsplot, name(WTPfromTT3, replace) yline(0) title(WTP from Travel Time - Cubic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
	ylabel(-40(10)40) ytick(-40(5)40)	  xlabel(0(.1).7,format(%03.2f)) xtick(0(.05).75)
*graph export .\results\appendix\figs\fig13_cubic.png, replace
*/
***************************************************************************************
********            Quartic Model
***************************************************************************************

qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr reliability_diff  , nocons  cluster(rt_id)
margins , at(TT_dif_hr=(0(.05).5)) post
est sto b4

/*marginsplot, name(WTPfromTT4, replace) yline(0) title(WTP from Travel Time - Quintic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
		  xlabel(0(.1).5,format(%03.2f)) xtick(0(.05).55)
*/

***************************************************************************************
********            Qintic Model
***************************************************************************************

qui reg charged_toll c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr##c.TT_dif_hr ///
	reliability_diff  , cluster(rt_id)  nocons 
margins , at(TT_dif_hr=(0(.05).5)) post
est sto b5

/* marginsplot, name(WTPfromTT3, replace) yline(0) title(WTP from Travel Time - Quintic Model with Constant) ///
	xtitle(Time Savings (in hours)) recast(line) recastci(rarea) plotopts( lc(black) ///
	 lp(dash) ) ciopts(fc(gs8%40) lw(none)) ///
	ytitle("Predicted WTP from Travel Time Savings" "(in dollars)") ///
		  xlabel(0(.1).5,format(%03.2f)) xtick(0(.05).55) */
*graph export .\results\appendix\figs\fig13_quintic.png, replace		


*********************************************************
****	Col 4	Power Model with Constant
*********************************************************

nl (charged_toll = {b1}*TT_dif_hr^{b2} + {b3}*reliability_diff) , ///
	initial( b1 10 b2 1 b3 10) vce(cl rt_id) variables(TT_dif_hr reliability_diff)
margins , at(TT_dif_hr=(0(.05).5)) post  
est sto b6
forval i=0/6{
	local `i'=`i'*5/60
}

coefplot b2 b3 b4 b5 b6 b1, at recast(line) cirecast(none) lc(black)  p1(lp(solid) lc(gs8)) ///
p2(lp(dot)) p3(lp(dash)) p4(lp(dash_dot)) p5(lp(shortdash))  p6(lp(longdash)) ///
		xlabel(`0' "0" `1' "5" `2' "10" `3' "15" `4' "20" `5' "25" `6' "30") ///
	 legend(order(12 2 4 6 8 10 )  label(2 "Quadratic") ///
 	label(4 "Cubic") label(6 "Quartic") label(8 "Quintic") label(10 "Power") ///
 	label(12 "Linear") region(lwidth(none)) row(1) ring(0) pos(12)) ///
	 ylabel(-20(10)20) ytick(-20(5)20) ytitle("WTP from Travel Time Savings (in dollars)", height(8) ) ///
 	xtitle("{&Delta}Travel Time (in minutes)") name(WTPfromTT_nocons, replace) ///
 	ciopts(fc(gs8%40) lw(none)) yline(0, lc(black))   plotregion(style(none) margin(zero)) 

graph export ".\results\maintablesfigs\figs\fig7.png", as(png) replace
